package com.hongdee.crm.question.controller;

import com.hongdee.crm.question.service.ITCrmQuestionGroupItemAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Name:
 * @Author: Liu XiaoLong
 * @Date: 2017/10/16 14:40
 * @Remark:
 */
@RestController
@RequestMapping("/crm/question/group/item/area")
public class TCrmQuestionGroupItemAreaController {
    @Autowired
    private ITCrmQuestionGroupItemAreaService itCrmQuestionGroupItemAreaService;

    @RequestMapping("/page")
    public Map page(@RequestParam(name = "uid",defaultValue = "") String uid,
                    @RequestParam(name = "token",defaultValue = "") String token,
                    @RequestBody Map data) throws Exception{
        Map map = new HashMap();
        List list = itCrmQuestionGroupItemAreaService.page(uid,data);
        map.put("dataList",list);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

    /**
     * @Name: 保存评分
     * @Author: Liu XiaoLong
     * @Date: 2017/10/17 10:35
     * @Remark:
     */
    @RequestMapping("/saveScore")
    public Map saveScore(@RequestParam(name = "uid",defaultValue = "") String uid,
                    @RequestParam(name = "token",defaultValue = "") String token,
                    @RequestParam(name = "id",defaultValue = "") String id,
                    @RequestParam(name = "score",defaultValue = "") int score,
                    @RequestParam(name = "questionId",defaultValue = "") String questionId,
                    @RequestParam(name = "itemId",defaultValue = "") String itemId) throws Exception{
        Map map = new HashMap();
            itCrmQuestionGroupItemAreaService.saveScore(id,score,itemId,questionId);
        //map.put("dataList",list);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }


    @RequestMapping("/save")
    public Map save(@RequestParam(name = "uid",defaultValue = "") String uid,
                         @RequestParam(name = "token",defaultValue = "") String token,
                         @RequestBody Map data ) throws Exception{
        Map map = new HashMap();
        itCrmQuestionGroupItemAreaService.saveOrUpdate(uid,data);
        //map.put("dataList",list);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

    @RequestMapping("/list")
    public Map getListByQuestionId(@RequestParam(name = "uid",defaultValue = "") String uid,
                         @RequestParam(name = "token",defaultValue = "") String token,
                         @RequestParam(name = "questionId",defaultValue = "") String questionId) throws Exception{
        Map map =  itCrmQuestionGroupItemAreaService.getListByQuestionId(uid,questionId);
        //map.put("dataList",list);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

}
